package com.ytxg.controller.front;

import com.google.gson.Gson;
import com.ytxg.dto.BookChapterRespDto;
import com.ytxg.dto.BookContentAboutRespDto;
import com.ytxg.dto.BookInfoRespDto;
import com.ytxg.service.IBookInfoService;
import com.ytxg.util.resp.RestResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 小说信息 前端控制器
 * </p>
 *
 * @author YT_XG
 * @since 2023-12-09
 */
//@CrossOrigin(originPatterns = "*",allowCredentials = "true")
@RequestMapping("/api/front/book")
//@Controller
@RestController
public class BookInfoController {
    @Autowired
    private IBookInfoService bookInfoService;

    /**
     * 小说章节列表查询接口
     */
    @GetMapping("chapter/list")
    public RestResp<List<BookChapterRespDto>> listChapters(Long bookId) {
        return bookInfoService.listChapters(bookId);
    }

    /**
     * 小说内容相关信息查询接口
     */
    @GetMapping("content/{chapterId}")
    public RestResp<BookContentAboutRespDto> getBookContentAbout(@PathVariable("chapterId") Long chapterId) {
        return bookInfoService.getBookContentAbout(chapterId);
    }


    /**
     * 小说信息查询接口
     */

    @GetMapping("{id}")
//    @ResponseBody
    public RestResp<BookInfoRespDto> getBookById(@PathVariable("id") Long bookId) {
//    public String getBookById(@PathVariable("id") Long bookId) {
        RestResp<BookInfoRespDto> bookById = bookInfoService.getBookById(bookId);
//        return  new Gson().toJson(bookById);
        return bookById;
    }

    @GetMapping("book/{id}")
    public String getBook(@PathVariable("id") Long bookId) {
        return "bookById";
    }
}
